<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<%@ taglib prefix="limits" uri="/WEB-INF/tld/limits.tld"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>zTree</title>
<link rel="stylesheet" type="text/css"
	href="../static/js/themes/defalut.css">
<link rel="stylesheet" type="text/css"
	href="../static/js/themes/public.css">
<link rel="stylesheet" type="text/css"
	href="../static/js/themes/ddspstyle.css">
<link rel="stylesheet" type="text/css"
	href="../static/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="../static/js/themes/icon.css">
<script type="text/javascript" src="../static/js/jquery.min.js"></script>
<script type="text/javascript" src="../static/js/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="../static/js/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="../static/js/jquery.validate.js"></script>
<script type="text/javascript" src="../static/js/index.js"></script>

<link rel="stylesheet" type="text/css"
	href="../static/zTree/css/zTree.css">
<link rel="stylesheet" type="text/css"
	href="../static/zTree/css/zTreeStyle/zTreeStyle.css">
<link rel="stylesheet" type="text/css"
	href="../static/js/themes/default/easyui.css">
<script type="text/javascript"
	src="../static/zTree/js/jquery.ztree.core.js"></script>
<script type="text/javascript"
	src="../static/zTree/js/jquery.ztree.excheck.js"></script>
<script type="text/javascript"
	src="../static/zTree/js/jquery.ztree.exedit.js"></script>
<script type="text/javascript" src="../static/js/attribute/zTreeInit.js"></script>
<script type="text/javascript">
function EasyuiDatagrid(f_pa_resourceId) {
	$("#easyui-datagrid").datagrid({
		url: 'attribute_list.do?f_pa_resourceId='+f_pa_resourceId,
		nowrap: true,
		striped: true,
		border: false,
		fit: true,
		rownumbers:true,
		columns: [[
			{field:'f_pa_id',checkbox:true},
			{field:'f_pa_name',title:'属性名称',align:'center',width:150},
			{field:'f_pa_desc',title:'简介',align:'center',width:150},
			{field:'f_pa_url',title:'属性路径',align:'center',width:150},
			{field:'f_pa_status',title:'状态',align:'center',width:50,
				formatter:function(value,row,index) {
					var status = "未知";
					if(value==1){
						status="有效";
					} else if(value==2){
						status="无效";
					} else {
						status="未知";
					}
					return status;
				}	
			},
			{field:'_parentId',title:'操作',align:'center',width:200,
				formatter:function(value,row,index){
					str ="";
					str= '<limits:uiAuth url="del_attribute.do"><a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="onClickBtnDelete(\''+row.f_pa_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-remove l-btn-icon-left">删除</span></span></a></limits:uiAuth>';
					str+= '<limits:uiAuth url="attribute_edit.jsp"><a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="edit(\''+row.f_pa_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-edit l-btn-icon-left">修改</span></span></a></limits:uiAuth>';
		    		str+= '<limits:uiAuth url="attribute_show.jsp"><a class="easyui-linkbutton l-btn l-btn-plain" iconCls="icon-ok" href="javascript:void(0);" plain="true" onclick="show(\''+row.f_pa_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-search l-btn-icon-left">详情</span></span></a></limits:uiAuth>';
			    	return str;
		    	}
			}
		]],
		singleSelect:false,
		pagination:true,
		pageList:[10,20,30,40,50],
		pageSize:10,
		toolbar: '#toolbar',
		
		onExpandRow: function(index,row){
		
		},
		onSelect: function(rowIndex,rowData) {
			
		},
		onUnselect: function(rowIndex,rowData) {
			
		},
		onCheckAll: function(rowIndex,rowData) {
			
		},
		onUncheckAll: function(rowIndex,rowData) {
		
		},
		onLoadSuccess: function(data) {
			if(data.total==-1) {
				$.messager.defaults={ok:"确定",cancel:"取消"};
				$.messager.confirm('提示', '用户尚未登录,请登录', function(r){
				if (r){
				    window.parent.location.href='/index.jsp';
				    return false;
				}});
			}
		}
	});
}

$(function(){
	$("#right").hide();
	gotoSearch = function(){
		$("#easyui-datagrid").datagrid('reload');
	};
	onClickBtnDelete = function(id){
		$.messager.confirm('确定删除角色','确定删除角色么?',function(r){
			if(r){
				app_ajax('del_attribute.do?f_pa_id='+id,
				'',
				function(msg){
					if(msg.success) {
						alert("删除成功!");
						if (checkAjaxRequestValidity(msg)) {
							gotoSearch($('#easyui-treegrid'));
						}
					} else {
						alert("删除异常，请联系管理员");
						if($.isFunction(window.showMessager)){
							window.showMessager(msg.resultTitle,msg.result);
						}
					}
				}
				);
			}
		});
	};
});

function SubgridTabOnSelect(title,index){
	setTimeout(function(){
		$("#easyui-datagrid").datagrid('fixDetailRowHeight',index);
	},300);
	setTimeout(function(){
		$("#easyui-datagrid").datagrid('fixDetailRowHeight',index);
	},3000);
}

function load(){
	$(".datagrid-row-expander datagrid-row-expand").attr("display","none"); 
}

function onpress(){
	var event=arguments.callee.caller.arguments[0]||window.event;//消除浏览器差异
		  	if (event.keyCode == 13){  
  			gotoSearch($('#easyui-treegrid'));
		}
}

function edit(id){
	openDialog($("#dlg"),'attribute_edit.jsp?f_pa_id='+id);
}

function show(id){
	openDialog($('#dlg'),'attribute_show.jsp?f_pa_id='+id);
}

function add(){
	var resourceId = $("#f_pa_resourceId").val();
	openDialog($('#dlg'),'attribute_add.jsp?f_pa_resourceId='+resourceId);
}
</script>
</head>
<body style="background: #f4f4f4;" onload="load()">
	<div id="left"
		style="width: 20%; overflow: auto; float: left; background: #d2e0f2;">
		<ul id="ztree" class="ztree" style="background: #f4f4f4;"></ul>
	</div>
	<div id="right"
		style="width: 79%; height: 80%; float: right; border-left: solid 1px">
		<table id="easyui-datagrid" title="属性列表"></table>
		<input type="hidden" name="f_pa_resourceId" id="f_pa_resourceId"
			value="" />
		<div id="toolbar" class="easyui_datagrid_toolbar">
			<div class="easyuiSearch">
				<limits:uiAuth url="attribute_add.jsp">
					<a href="javascript:void(0);" class="easyui-linkbutton"
						data-options="iconCls:'icon-add', plain:true" onclick="add()">增加属性</a>
				</limits:uiAuth>
			</div>
		</div>
		<div id="dlg" class="easyui-dialog"
			style="width: 600px; height: 470px; padding-top: 0px;"
			data-options="title:'角色详情', iconCls:'icon-save',modal:true,closed:true,buttons:'#dlg_buttons'">
			<iframe scrolling="auto" frameborder="0"
				style="width: 100%; height: 99%;"></iframe>
		</div>
	</div>
</body>
</html>